﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DALScolarite;
namespace Scolarite 
{
    public partial class Anneeuniv : Form
    {
        public Anneeuniv()
        {
            InitializeComponent();
        }

        private void btsave_Click(object sender, EventArgs e)
        {
            scolarite_anneeuniv ann = new scolarite_anneeuniv
            { 
                idAnneeUniv = idAnneeUnivTextBox.Text,
                labelar = labelarTextBox.Text,
                labelfr = labelfrTextBox.Text
            
            };

             uvtmoyEntities ent = new uvtmoyEntities();
             scolarite_anneeuniv verifann = ent.scolarite_anneeuniv.Find(idAnneeUnivTextBox.Text);
             if (verifann != null)
             {
                 ent.scolarite_anneeuniv.Attach(ann);
                 ent.Entry(ann).State = EntityState.Modified;
             }
             else
             {
                    ent.scolarite_anneeuniv.Add(ann);
             }
           
            ent.SaveChanges();
            scolarite_anneeunivBindingSource.DataSource = GlobalParams.MonDbcontext.scolarite_anneeuniv.ToList();
        }

        private void Anneeuniv_Load(object sender, EventArgs e)
        {
            scolarite_anneeunivBindingSource.DataSource = GlobalParams.MonDbcontext.scolarite_anneeuniv.ToList();
        }

        private void btsupprimer_Click(object sender, EventArgs e)
        {
            uvtmoyEntities ent = new uvtmoyEntities();
            scolarite_anneeuniv verifann = ent.scolarite_anneeuniv.Find(idAnneeUnivTextBox.Text);
            if (verifann != null)
            {
                ent.scolarite_anneeuniv.Remove(verifann);
                ent.SaveChanges();
                scolarite_anneeunivBindingSource.DataSource = GlobalParams.MonDbcontext.scolarite_anneeuniv.ToList();
            }
        }

        private void btadd_Click(object sender, EventArgs e)
        {
            scolarite_anneeunivBindingSource.AddNew();
        }
    }
}
